/*
 * responce.h
 *
 *  Created on: 2021年8月16日
 *      Author: pengzc
 */

#ifndef HTTP_HTTP_RESPONSE_H_
#define HTTP_HTTP_RESPONSE_H_

#include <string>
#include <map>
#include <iostream>
#include <fstream>

namespace http {

class HTTPClient;

class HTTPResponse {
public:
  HTTPResponse();
  virtual ~HTTPResponse();

  int status();
//  int ErrorCode();
  std::string body();
//  std::string ErrorMessage();
  std::string header(const std::string& key);
  std::map<std::string, std::string> header_;

  /**
   * -读取Header中的Content-Length
   *
   * @return 如果该字段不存在，返回 -1
   */
  int getContentLength() const;

  std::string getContentType() const;

  std::string* mutable_body();

  std::string toString();

  const std::string& reasonText() const;

private:
  friend class HTTPClient;
  std::string body_;
  int status_code_;
  std::string reason_text_;

  FILE* dst_file_;

  double total_time = 0;
  double name_lookup_time = 0;
  double connect_time = 0;
  double app_connect_time = 0;
  double pre_transfer_time = 0;
  double start_transfer_time = 0;
  double redirect_time = 0;
  int redirect_count = 0;
};

} /* namespace http */

#endif /* HTTP_HTTP_RESPONSE_H_ */
